package com.dyh.controller.admin;

import com.dyh.pojo.User;
import com.dyh.service.user.UserService;
import com.dyh.service.user.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/admin")
@RestController
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/queryUserList")
    public List<User> queryUserList(){
        List<User> userList=userService.queryUserList();
        for (User user : userList) {
            System.out.println(user);
        }
        return userList;
    }

    //添加一个用户
    @RequestMapping("/addUser")
    public String addUser(){
        userService.addUser(new User(2,"dyh","123456","男",19,"owner","1111","1111","user:add"));
        return "ok";
    }

    //修改一个用户
    @RequestMapping("/updateUser")
    public String updateUser(){
        userService.updateUser(new User(1,"root","123456","男",19,"管理员","1111","1111","user:delete"));
        return "ok";
    }

    //注销一个用户
    @RequestMapping("/deleteUser")
    public String deleteUser(){
        userService.deleteUser(2);
        return "ok";
    }

    //保存一个用户
    @RequestMapping("/save")
    public String save(User user){
        userService.save(user);
        return "ok";
    }


}
